package javaVersion.learn.checkPoint;

import javaVersion.pojo.SEvent;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;

import java.util.concurrent.TimeUnit;

/**
 * @program: myFlink
 * @description: 每1秒统计4秒中窗口中的数据量，对结果进行CheckPoint
 * @author: WincoMa
 * @create: 2020-07-23 14:54
 **/
public class Eg1_SEventSourceWithChk extends RichSourceFunction<SEvent> {
    private boolean isRunning = true;
    //自定义数据源，需要继承RichSourceFunction
    //每秒钟向流图中注入10000个元组
    @Override
    public void run(SourceContext<SEvent> ctx) throws Exception {
        while (isRunning) {
            for (int i = 0; i < 1000; i++) {
                //编写测试数据，并循环生成1000个POJO，作为数据源
                ctx.collect(new SEvent(1,"hello-" + i,"test-info",1));
                //每1秒生成一次数据
                TimeUnit.SECONDS.sleep(1);
            }
        }
    }

    @Override
    public void cancel() {
        isRunning = false;
    }
}
